const path = require('path');
const px2rem = require('postcss-px2rem');
const autoprefixer = require('autoprefixer');

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'px2rem-loader',
            // options here
            options: {
              remUni: 37.5,
              remPrecision: 8,
            },
          },
        ],
      },
      {
        test: /\.css$/,
        include: /node_modules/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'px2rem-loader',
            // options here
            options: {
              remUnit: 37.5,
              baseDpr: 1,
            },
          },
        ],
      },
      {
        test: /\.less$/,
        exclude: /node_modules/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              plugins: [autoprefixer, px2rem({ remUnit: 37.5, baseDpr: 1 })],
            },
          },
          'less-loader',
        ],
      },
      {
        test: /\.less/,
        include: /node_modules/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'less-loader',
            options: {
              javascriptEnabled: true,
            },
          },
        ],
      },
      {
        test: /\.(svg)$/,
        exclude: /node_modules/,
        use: [
          'url-loader?limit=10000',
        ],
      },
    ],
  },
  resolve: {
    alias: {
      '@/common': path.join(process.cwd(), 'client/common'),
      '@/app': path.join(process.cwd(), 'client/app'),
    },
  },
  devtool: 'hidden-source-map',
};
